import type { OperPermissionType } from "/@/api/aiot/role/models";

export enum MenuType {
  FEATURE = "Feature",
  FUNCTION = "Function",
  OPERATION = "Operation",
}

export interface MenuItem {
  id: string;
  applicationId?: string;
  functionId: string;
  parentFunctionInnerId?: string;
  functionInnerId?: string;
  //菜单管理页面的菜单多语言key
  functionName: string;
  code?: string;
  functionIcon?: string;
  functionUrl: string;
  action?: string;
  functionType: FunctionType;
  isActive?: boolean;
  isHidden?: boolean;
  //首页获取菜单数据返回的菜单多语言key
  name?: string;
  //首页获取菜单数据返回的菜单多语言key对应的语言值，作为MenuItem的title
  title?: string;
  optionsType?: string;
  rootId?: string;
  sortValue: number;
  type?: MenuType;
  children?: MenuItem[];
  //保留所有菜单的children数据，因为首页菜单页面如果有按钮数据的话，需要移除，同时将按钮数据赋值给_children
  _children?: MenuItem[];
  disabled?: boolean;
  _isAdd?: boolean;
  _hideUp?: boolean;
  _hideDown?: boolean;
  _manageChecked?: boolean;
  _checkChecked?: boolean;
  _manageIndeterminate?: boolean;
  _checkIndeterminate?: boolean;
}

export type PartialMenuItem = Partial<MenuItem>;

export interface MenuSearchModel {
  appId: string;
}

export enum FunctionType {
  //平台级功能
  PLATFORM = 0,
  //企业级功能,需要授权或设置角色后使用
  ENTERPRISE = 1,
  //公共功能(无需设置或授权)
  COMMON = 2,
}

export const FuncitonTypeName = {
  [FunctionType.PLATFORM]: "platform",
  [FunctionType.ENTERPRISE]: "enterprise",
  [FunctionType.COMMON]: "common",
};

export interface Operation {
  id?: string;
  code?: string;
  icon?: string;
  name?: string;
  type?: OperPermissionType;
}

export interface FunctionItem {
  name?: string;
  description?: string;
  displayOrder?: number;
  functionId?: string;
  functionIcon?: string;
  functionName?: string;
  functionType?: FunctionType;
  functionUrl?: string;
  isActive?: number;
  isFolder?: number;
  isHidden?: number | boolean;
  remark?: string;
  operations?: Operation[];
  appFeatureId?: string;
  applicationId?: string;
  parentFunctionInnerId?: string;
}

export interface SortParams {
  childDisplayOrder: number;
  childFunctionId: string;
  parentDisplayOrder: number;
  parentFunctionId: string;
}
